import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ahj_app/base/utils/downloadfile/OpenFileUtils.dart';
import 'package:flutter_ahj_app/base/utils/downloadfile/downFilePage.dart';
import 'package:flutter_ahj_app/base/utils/permission/PerUtils.dart';
import 'package:flutter_ahj_app/base/utils/permission/permissionGroup.dart';
import 'package:path_provider/path_provider.dart';

import 'package:permission_handler/permission_handler.dart';
class DownFilesUtils {
  ///跳转下载附件页面
  static downLoad(BuildContext context, String fileName, String downUrl) async {
    String filePath = "";
    String result =
        await PerUtils.checkPermission(context, [Permission.storage]);
    if (result == "1") {

     
      if (Platform.isIOS) {
        final dir = await getApplicationDocumentsDirectory();
        // 创建文件夹
        var directory = new Directory(
            "${dir.path + Platform.pathSeparator}aqzjzx${Platform.pathSeparator}files");
        filePath = directory.path + Platform.pathSeparator + fileName;
      
        
      } else {

         final dir = await getExternalStorageDirectory();
        // 创建文件夹
        var directory = new Directory(
            "${dir.path + Platform.pathSeparator}aqzjzx${Platform.pathSeparator}files");
        filePath = directory.path + Platform.pathSeparator + fileName;

       
      }

      Navigator.push(
          context,
          new MaterialPageRoute(
              builder: (context) => DownFilePage(downUrl, filePath, fileName)));
    }
  }
}
